//
//  UINavigationBar+Additions.m
//  DJAppModule
//
//  Created by Lynn_Lin on 2018/3/23.
//

#import "UINavigationBar+Additions.h"
#import "UIImage+Additions.h"
#import "UIColor+Additions.h"

@implementation UINavigationBar (Additions)
- (void)hiddenBottomHairline:(BOOL)hidden
{
    UIImageView *lineImgV = [self findHairlineImageViewUnder:self];
    lineImgV.hidden = hidden;
    UIImage *nvaBgImg = hidden ? [UIImage createImageWithColor:[UIColor colorWithRed:249/255.f green:249/255.f blue:249/255.f alpha:1]] : [UIImage imageNamed:@"navbg_gray_640_109"];
    [self setBackgroundImage:[nvaBgImg stretchableImageWithLeftCapWidth:0 topCapHeight:0]
               forBarMetrics:UIBarMetricsDefault];
}

- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}
@end
